import { computed } from 'vue';
import { useAppStore } from '@/store/modules/app';
import { type ProjectConfig } from '@/settings/types';

export function useRootSetting() {
  const appStore = useAppStore();

  const getAppTheme = computed(() => appStore.getProjectConfig.theme);
  const getIsDark = computed(() => appStore.getProjectConfig.theme === 'dark');

  const getOpenKeepAlive = computed(() => appStore.getProjectConfig.openKeepAlive);
  const getCanEmbedIFramePage = computed(() => appStore.getProjectConfig.canEmbedIFramePage);

  /** 获取是否使用全局错误捕获 */
  const getUseErrorHandle = computed(() => appStore.getProjectConfig.useErrorHandle);

  function setRootSetting(setting: DeepPartial<ProjectConfig>) {
    appStore.setProjectConfig(setting);
  }

  return {
    getUseErrorHandle,
    getCanEmbedIFramePage,
    getAppTheme,
    getIsDark,
    setRootSetting,
    getOpenKeepAlive
  };
}
